let mixins = {
  data(){
    return {
      path:"",

      info:{},

      codeLeftTime:120,//获取验证码间隔
      settime:null,
      userInfo:{}
    }
  },
  methods:{
    init(){
      let left_time = localStorage.getItem(localSaved.leftTime)
      if(left_time>0&&left_time!=120){
        this.codeLeftTime=left_time
        clearInterval(this.settime)
        this.setCodeTime()
      }
    },
    /**
     * @name 获取验证码
     */
    getCheckCode(){
      let params={
        phone:this.info.phone
      }
      this.setCodeTime()
      _g.apiPost('iuser/getSMS.do',params,true).then(res=>{
        _g.toMessage({status:res.status,msg:res.status==0?"验证码已发送":(res.msg||res.data)})
      })
    },
    /**
     * @name 设置验证码延时
     */
    setCodeTime(){
      this.settime=setInterval(()=>{
        this.codeLeftTime--
        localStorage.setItem(localSaved.leftTime,this.codeLeftTime)
        if(this.codeLeftTime==0){
          clearInterval(this.settime)
          this.codeLeftTime=120
          localStorage.setItem(localSaved.leftTime,this.codeLeftTime)
        }
      },1000)
    },
    
    /**
     * @name 获取信息
     */
    getUserInfo(){
      let userInfo = localStorage.getItem(localSaved.userInfo)
      if(userInfo)this.userInfo=JSON.parse(userInfo)
      this.path = _g.getRouterPath(this)
    },

    /**
     * @name 重写个人信息
     */
    rewriteInfo(params){
      let userInfo = JSON.parse(localStorage.getItem(localSaved.userInfo))
      for(var key in params){
        userInfo[key]=params[key]
      }
      localStorage.setItem(localSaved.userInfo,JSON.stringify(userInfo))
    },
  },
  created() {
    this.getUserInfo()
  },
}

export default mixins